<template>
    <div class="member-layout">
        <div class="list">
            <div class="search-part">
                <div class="part1">
                    <el-row :gutter="20">
                        <el-col :span="8">
                            <div class="grid-content">
                                <v-simpsearch class="simple-search" @transferParam="getParam"></v-simpsearch>
                            </div>
                        </el-col>
                    </el-row>
                </div>
            </div>
        </div>
        <div class="memeber-manage-con">
            <div class="block"  style="padding-left: 20px">
                <label class="date-tips">选择日期：</label>
                <el-date-picker
                        v-model="dateValue"
                        type="date"
                        placeholder="选择日期时间"
                        @change="change(dateValue)">
                </el-date-picker>
            </div>
            <el-table
                    :data="information.data"
                    border
                    style="width: 100%">
                <el-table-column
                        prop="oname"
                        label="所属机构"
                        align="left">
                </el-table-column>
                <el-table-column
                        prop="gname"
                        label="商品名称"
                        align="left">
                </el-table-column>
                <el-table-column
                        prop="snm"
                        label="库存数量"
                        align="left"
                        width="140">
                </el-table-column>
                <el-table-column
                        prop="itt"
                        label="在途数量"
                        align="left"
                        width="140">
                </el-table-column>
                <el-table-column
                        prop="fup"
                        label="冻结数量"
                        align="left"
                        width="140">
                </el-table-column>
            </el-table>
            <pagination :total="information.pagination.total" align="right" :change="onTableChange"
                        :pageSizeChange="handlePageSizeChange" :page-size="pageSize" :size-options="[20, 30, 50]"
                        v-if="true"></pagination>
        </div>
    </div>
</template>

<script>
    import moment from 'moment';
    import vSimpsearch from '../SimpSearch.vue';
    export default {
        name: 'keepalive-false',
        components: {
            vSimpsearch
        },
        data: function () {
            return {
                dateValue: new Date().toLocaleDateString(),
                pageSize: 20,
                information: {
                    pagination: {},
                    data: []
                },
                param: ""
            }
        },
        created(){
            this.$$("#content").scrollTop(0)
            this.getData(1);

        },
        watch: {
            param(val){
                this.information.data = [];
                this.information.pagination.current = 1;
                this.information.pagination.total = 1;
                this.getData(1);
            }
        },
        methods: {
            change(dateValue){
                console.log(moment(dateValue).format('YYYY-MM-DD'));

                this.getData(1);
            },
            //获取数据
            getData(current){
                let selectDate =  moment(this.dateValue).format('YYYY-MM-DD');
                let param = {
                    page: current,
                    rows: this.pageSize,
                    date: selectDate,
                    param: this.param
                }
                let self = this;
                this.$axioxs.get('/goodsStock/day-report?'+ this.$qs.stringify(param)).then(function (res) {
                    let data = res.data;
                    let pageinfo = {};
                    pageinfo.total = data.count;
                    pageinfo.pageSize = data.rows;
                    console.log(pageinfo.pageSize)
                    pageinfo.current = data.page;
                    pageinfo.last_page = data.totalPage;
                    self.information.pagination = pageinfo;
                    self.information.data = data.records;
                })
            },
            onTableChange(current){
                console.log(current);
                this.getData(current);

            },
            handlePageSizeChange(current, pageSize) {
                console.log('pageSize', pageSize);
                this.pageSize = Number(pageSize);
                this.onTableChange(1);

            },
            getParam(res){
                console.log(res);
                this.param = res;
                this.$$("#content").scrollTop(0)
            }
        }
    }

</script>
<style scoped>
    .memeber-manage-con{
        padding-top: 77px;
    }
</style>